home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / outcode / outcode4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  861 b   |  33 lines

  1. /* Direct calculation of 4D outcodes, C code fragment */
  2.  
  3. /* number of bits in a word */
  4. #define NUMBITS       sizeof(long)*8
  5.  
  6. /* get the integral form of a floating point number */
  7. #define v(x)       *(long *) &(x)
  8.  
  9. /* get the sign bit of an integer as a value 0 or 1 */
  10. #define s(x)       (((unsigned long)(x)) >> (NUMBITS-1))
  11.  
  12. /* get the absolute value of a floating point number in integral form */
  13. #define a(x)       ((x) & ~(1 << (NUMBITS-1)))
  14.  
  15.     iw = v(w);
  16.     abs_w = a(iw);
  17.     outcode = s(iw);      /* 0 or 1 per w's sign */
  18.  
  19.     ix = v(x);
  20.     diff = s(abs_w - a(ix));
  21.     t = s(ix) + 1;
  22.     outcode |= diff << t;      /* 0, 2, or 4 or'd with outcode */
  23.  
  24.     iy = v(y);
  25.     diff = s(abs_w - a(iy));
  26.     t = s(iy) + 3;
  27.     outcode |= diff << t;      /* 0, 8, or 16 or'd with outcode */
  28.  
  29.     iz = v(z);
  30.     diff = s(abs_w - a(iz));
  31.     t = s(iz) + 5;
  32.     outcode |= diff << t;      /* 0, 32, or 64 or'd with outcode */
  33.